home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr09 / vstsrc.zip / DIALOGS.C < prev    next >
C/C++ Source or Header  |  1995-02-02  |  29KB  |  822 lines

  1. /*
  2.  * %W% %E% %U%  [EXTREL_1.2]
  3.  *
  4.  * VersaTrack orbit calculations are based on those that appear in Dr. Manfred
  5.  * Bester's sattrack program (the Unix(tm) versions 1 and 2).
  6.  *
  7.  * The data from which the maps where generated come from "xsat", an
  8.  * X-Windows program by David A. Curry (N9MSW).
  9.  *
  10.  * Site coordinates come from various sources, including a couple of
  11.  * World Almanacs, and also from both of the programs mentioned above.
  12.  *
  13.  * The following are authors' applicable copyright notices:
  14.  *
  15.  *                                                                               
  16.  * Copyright (c) 1992, 1993, 1994 Manfred Bester. All Rights Reserved.        
  17.  *                                                                           
  18.  * Permission to use, copy, modify, and distribute this software and its      
  19.  * documentation for educational, research and non-profit purposes, without   
  20.  * fee, and without a written agreement is hereby granted, provided that the  
  21.  * above copyright notice and the following three paragraphs appear in all    
  22.  * copies.                                                                    
  23.  *                                                                              
  24.  * Permission to incorporate this software into commercial products may be    
  25.  * obtained from the author, Dr. Manfred Bester, 1636 M. L. King Jr. Way,     
  26.  * Berkeley, CA 94709, USA.                                                   
  27.  *                                                                             
  28.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,  
  29.  * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF    
  30.  * THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR HAS BEEN ADVISED   
  31.  * OF THE POSSIBILITY OF SUCH DAMAGE.                                         
  32.  *                                                                             
  33.  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT       
  34.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A    
  35.  * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"       
  36.  * BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,  
  37.  * UPDATES, ENHANCEMENTS, OR MODIFICATIONS.                                   
  38.  *                                                                             
  39.  *                                                                             
  40.  * Copyright 1992 by David A. Curry                                            
  41.  *                                                                             
  42.  * Permission to use, copy, modify, distribute, and sell this software and its 
  43.  * documentation for any purpose is hereby granted without fee, provided that  
  44.  * the above copyright notice appear in all copies and that both that copyright
  45.  * notice and this permission notice appear in supporting documentation.  The  
  46.  * author makes no representations about the suitability of this software for  
  47.  * any purpose.  It is provided "as is" without express or implied warranty.   
  48.  *                                                                             
  49.  * David A. Curry, N9MSW                                                       
  50.  * Purdue University                                                           
  51.  * Engineering Computer Network                                                
  52.  * 1285 Electrical Engineering Building                                        
  53.  * West Lafayette, IN 47907                                                    
  54.  * davy@ecn.purdue.edu                                                         
  55.  *                                                                             
  56.  * VersaTrack Copyright (c) 1993, 1994 Siamack Navabpour. All Rights Reserved.
  57.  *
  58.  * Permission is hereby granted to copy, modify and distribute VersaTrack
  59.  * in whole, or in part, for educational, non-profit and non-commercial use
  60.  * only, free of charge or obligation, and without agreement, provided that
  61.  * all copyrights and restrictions noted herein are observed and followed, and
  62.  * additionally, that the above copyright notice and all other copyright
  63.  * notices listed herein, as well as the accompanying text appear unaltered
  64.  * in all copies and in all derived work.
  65.  *
  66.  * This notice shall not in any way void or supersede any of the other authors
  67.  * rights or privileges.
  68.  *
  69.  * VersaTrack IS PRESENTED FREE AND "AS IS", WITHOUT ANY WARRANTY OR SUPPORT.
  70.  * YOU USE IT AT YOUR OWN RISK. The author(s) shall not be liable for any
  71.  * direct, indirect, incidental, or consequential damage, loss of profits or
  72.  * other tangible or intangible losses or benefits, arising out of or related
  73.  * to its use. VersaTrack carries no warranty, explicit or implied, including
  74.  * but not limited to those of merchantablity and fitness for a particular
  75.  * purpose.
  76.  *
  77.  * Siamack Navabpour, 12342 Hunter's Chase Dr. Apt. 2114, Austin, TX 78729.
  78.  * sia@bga.com or sia@realtime.com.
  79.  */
  80.  
  81. /*
  82.  * Routines to select satellites sites and various attributes and to
  83.  * manipulate the active list.
  84.  *
  85.  * Needs to be re-done.
  86.  */
  87.  
  88. #include <windows.h>
  89. #include <stdio.h>
  90. #include <math.h>
  91. #include <time.h>
  92.  
  93. #include "resource.h"
  94. #include "vstdefs.h"
  95. #include "constant.h"
  96. #include "vsttype.h"
  97. #include "vstextrn.h"
  98.  
  99. static HWND hSiteListbox, hSatListbox, hSite, hSatellite, hDuration;
  100. static HWND hMinElevation, hSelbox, hStartTime, hStepTime;
  101. static int lsat=-1, lsite=-1, sbid=-1;
  102. static satellite_t *osatp;
  103. static site_t *ositep;
  104. static double od, ost, osp, om;
  105. static int ou;
  106.  
  107. void
  108. MoreHook(HWND hwnd, select_t *selp, satellite_t *satp,
  109.          site_t *sitep, int *flagp)
  110. {
  111.     extern void *LibFunc(const char *), LibClose(void);
  112.     void (*SettingsHook)(int, HWND, select_t *, satellite_t *, site_t *, int *);
  113.  
  114.     SettingsHook = (void (*)) LibFunc("SettingsHook");
  115.     if (SettingsHook == NULL) {
  116.         LibClose();
  117.         usermsg(dllinvalidmsg);
  118.     }
  119.     else
  120.         (*SettingsHook)(VSTVERSION, hwnd, selp, satp, sitep, flagp);
  121. }
  122.  
  123. struct ButtonTag {
  124.     int fval, bval, oldf;
  125. };
  126.  
  127. static struct ButtonTag BtnTab[16] = {
  128.     SE_RTD_BOA,     IDC_SETTINGS_RTD_BOA,  0,
  129.     SE_RTD_POA,     IDC_SETTINGS_RTD_POA,  0,
  130.     SE_RTD_BEEP,    IDC_SETTINGS_RTD_BEEP, 0,
  131.     SE_RTD_BMP,     IDC_SETTINGS_RTD_BMP,  0,
  132.     SE_RTD_DIC,     IDC_SETTINGS_RTD_DIC,  0,
  133.     SE_RTD_UTC,     IDC_SETTINGS_RTD_UTC,  0,
  134.     SE_RTD_LOC,     IDC_SETTINGS_RTD_LOC,  0,
  135.     SE_RTD_SLT,     IDC_SETTINGS_RTD_SLT,  0,
  136.     SE_GTR_UTC,     IDC_SETTINGS_GTR_UTC,  0,
  137.     SE_GTR_LOC,     IDC_SETTINGS_GTR_LOC,  0,
  138.     SE_GTR_SLT,     IDC_SETTINGS_GTR_SLT,  0,
  139.     SE_RTD_HIC,     IDC_SETTINGS_RTD_HIC,  0,
  140.     SE_RTD_SIM,     IDC_SETTINGS_SIMULATE, 0,
  141.     SE_RTD_USERA,    IDC_SETTINGS_UA, 0,
  142.     SE_RTD_USERB,    IDC_SETTINGS_UB, 0,
  143.     -1,             -1,
  144. };
  145.  
  146.  
  147. void
  148. setbutton(HWND hwnd, int id, BOOL flag)
  149. {
  150.     SendDlgItemMessage(hwnd, id, BM_SETCHECK, flag ? (WPARAM) 1 : 0, (LPARAM) 0);
  151. }
  152.     
  153.  
  154. #define flag_toggle(flagp, value)    *flagp ^= value
  155.  
  156. static void
  157. clrbtnflgs()
  158. {
  159.     register struct ButtonTag *btp;
  160.     for (btp = BtnTab; btp->fval != -1; btp++)
  161.         btp->oldf = 0;
  162.     om = ost = od = osp = -2.0;
  163.     osatp = NULL, ositep = NULL;
  164.     ou = -2;
  165. }
  166.  
  167. static void
  168. setbuttons(HWND hwnd, int state)
  169. {
  170.     register struct ButtonTag *btp;
  171.     int p;
  172.  
  173.     for (btp = BtnTab; btp->fval != -1; btp++) {
  174.         p = btp->fval & state;
  175.         if (p != btp->oldf)
  176.             setbutton(hwnd, btp->bval, p ? TRUE : FALSE);        
  177.         btp->oldf = p;
  178.     }
  179. }
  180.  
  181.  
  182. static int
  183. checkbuttons(hwnd, wParam, flagp)
  184. HWND hwnd;
  185. WPARAM wParam;
  186. unsigned int *flagp;
  187. {
  188.     int cmd;
  189.  
  190.     cmd = LOWORD(wParam);
  191.  
  192.     switch (cmd) {
  193.     case IDOK:
  194.     case IDMORE:
  195.     case IDSAVE:
  196.     case IDMODIFY:
  197.     case IDADDSEL:
  198.     case IDDELSEL:
  199.     case IDC_SETTINGS_SHOWSAT:
  200.     case IDC_SETTINGS_SHOWLOC:
  201.         return cmd;
  202.     default:
  203.         break;
  204.     }
  205.     
  206.     if (HIWORD(wParam) != BN_CLICKED)
  207.         return -1;
  208.         
  209.     switch (cmd) {
  210.     case IDC_SETTINGS_RTD_BEEP:
  211.         flag_toggle(flagp, SE_RTD_BEEP);
  212.         goto bset;
  213.         
  214.     case IDC_SETTINGS_RTD_BOA:
  215.         flag_toggle(flagp, SE_RTD_BOA);
  216.         goto bset;
  217.  
  218.     case IDC_SETTINGS_RTD_POA:
  219.         flag_toggle(flagp, SE_RTD_POA);
  220.         goto bset;
  221.  
  222.     case IDC_SETTINGS_RTD_BMP:
  223.         flag_toggle(flagp, SE_RTD_BMP);
  224.         goto bset;
  225.  
  226.     case IDC_SETTINGS_RTD_DIC:
  227.         flag_toggle(flagp, SE_RTD_DIC);
  228.         goto bset;
  229.  
  230.     case IDC_SETTINGS_RTD_HIC:
  231.         flag_toggle(flagp, SE_RTD_HIC);
  232.         goto bset;
  233.         
  234.     case IDC_SETTINGS_SIMULATE:
  235.         flag_toggle(flagp, SE_RTD_SIM);
  236.         goto bset;
  237.         
  238.     case IDC_SETTINGS_UA:
  239.         flag_toggle(flagp, SE_RTD_USERA);
  240.         goto bset;
  241.         
  242.     case IDC_SETTINGS_UB:
  243.         flag_toggle(flagp, SE_RTD_USERB);
  244.         goto bset;
  245.         
  246.     case IDC_SETTINGS_RTD_SLT:
  247.         *flagp |= SE_RTD_SLT;
  248.         *flagp &= ~(SE_RTD_UTC|SE_RTD_LOC);
  249.         goto bset;
  250.  
  251.     case IDC_SETTINGS_RTD_UTC:
  252.         *flagp |= SE_RTD_UTC;
  253.         *flagp &= ~(SE_RTD_SLT|SE_RTD_LOC);
  254.         goto bset;
  255.  
  256.     case IDC_SETTINGS_RTD_LOC:
  257.         *flagp |= SE_RTD_LOC;
  258.         *flagp &= ~(SE_RTD_SLT|SE_RTD_UTC);
  259.         goto bset;
  260.  
  261.     case IDC_SETTINGS_GTR_SLT:
  262.         *flagp |= SE_GTR_SLT;
  263.         *flagp &= ~(SE_GTR_UTC|SE_GTR_LOC);
  264.         goto bset;
  265.                 
  266.     case IDC_SETTINGS_GTR_UTC:
  267.         *flagp |= SE_GTR_UTC;
  268.         *flagp &= ~(SE_GTR_SLT|SE_GTR_LOC);
  269.         goto bset;
  270.  
  271.     case IDC_SETTINGS_GTR_LOC:
  272.         *flagp |= SE_GTR_LOC;
  273.         *flagp &= ~(SE_GTR_SLT|SE_GTR_UTC);
  274.     bset:
  275.         setbuttons(hwnd, *flagp);
  276.         break;
  277.         
  278.      default: /* Warning: must return -1 */
  279.         break;
  280.      }
  281.      return -1;
  282. }
  283.  
  284. static void
  285. lselect(hwnd, index)
  286. HWND hwnd;
  287. int index;
  288. {
  289.     SendMessage(hwnd, LB_SETCURSEL, (WPARAM) index, (LPARAM) 0);
  290.     SendMessage(hwnd, LB_SETTOPINDEX, (WPARAM)
  291.         ( ((index-2) < 0) ? 0 : (index - 2) ) , (LPARAM) 0);
  292. }
  293.  
  294. static BOOL
  295. OnReturn(hwnd, selpp, satpp, sid, sitepp, stid,
  296.          startp, durp, stepp, minelevp, updp)
  297. HWND hwnd;
  298. select_t **selpp;
  299. satellite_t **satpp;
  300. int *sid;
  301. site_t **sitepp;
  302. int *stid;
  303. double *startp, *durp, *stepp, *minelevp;
  304. int *updp;
  305. {
  306.     satellite_t *satp;
  307.     site_t *sitep;
  308.     double f;
  309.     int d, error = FALSE;
  310.     select_t *sp;
  311.  
  312.     if (!(satp = findSatbyID(*sid))) {
  313.         GetEditText(hwnd, IDC_SETTINGS_SATELLITE, tmpbuf, BUFLEN);
  314.         if (!(satp = findSatbyName(tmpbuf))) {
  315.             usermsg("Satellite Not Found");
  316.             error = TRUE;
  317.         }
  318.     }
  319.     if (!error) {
  320.         *satpp = satp;
  321.            *sid = satp->s_lbid;
  322.         SendMessage(hSatellite, WM_SETTEXT, (WPARAM) 0, (LPARAM) satp->s_name);
  323.     }
  324.     if (!(sitep = findSitebyID(*stid))) {
  325.         GetEditText(hwnd, IDC_SETTINGS_LOCATION, tmpbuf, BUFLEN);
  326.         if (!(sitep = findSitebyName(tmpbuf))) {
  327.             usermsg("Site Not Found");
  328.                error = TRUE;
  329.            }
  330.     }
  331.     if (!error) {
  332.         *sitepp = sitep;
  333.            *stid = sitep->c_lbid;
  334.         sprintf(tmpbuf,"%s, %s",sitep->c_name, sitep->c_locale);
  335.            SendMessage(hSite, WM_SETTEXT, (WPARAM)0, (LPARAM) tmpbuf);
  336.        }
  337.     if (GetEditText(hwnd, IDC_SETTINGS_GTR_STEPTIME, tmpbuf, 64)) {
  338.         f = atof(tmpbuf);
  339.         if (f <= 0.0) {
  340.             usermsg("Step Time Cannot Be Negative Or Zero!");
  341.             error = TRUE;
  342.         }
  343.         else {
  344.             *stepp = f / SPD;
  345.         }
  346.     }
  347.     if (GetEditText(hwnd, IDC_SETTINGS_GTR_DURATION, tmpbuf, 64)) {
  348.         f = atof(tmpbuf);
  349.         if (f <= 0.0) {
  350.             usermsg("Duration cannot be negative or zero!");
  351.             error = TRUE;
  352.         }
  353.         else
  354.             *durp = f;
  355.     }
  356.     if (GetEditText(hwnd, IDC_SETTINGS_MINELEVATION, tmpbuf, 64)) {
  357.         if (sscanf(tmpbuf, "%lf", &f) != 1) {
  358.             usermsg("Invalid Value for Minimum Elevation"); 
  359.             error = TRUE;
  360.         }
  361.         else
  362.             *minelevp = f * CDR;
  363.     }
  364.     if (GetEditText(hwnd, IDC_SETTINGS_GTR_STARTTIME, tmpbuf, 64)) {
  365.         if (tmpbuf[0] == '*' && tmpbuf[1] == 0)
  366.             *startp = -1.0;
  367.         else {
  368.             if ((f = dateStrtoTime(tmpbuf)) < 0.0 ) {
  369.                 usermsg("Invalid Date/Time");
  370.                 error = TRUE;
  371.             }
  372.             else
  373.                 *startp = f;
  374.         }
  375.     }
  376.     if (GetEditText(hwnd, IDC_SETTINGS_RTD_UPD, tmpbuf, 64)) {
  377.         d = 0;
  378.         if (sscanf(tmpbuf, "%d", &d) != 1 || d <= 0) {
  379.             usermsg("Invalid Update Time");
  380.             error = TRUE;
  381.         }
  382.         else
  383.             *updp = d;
  384.     }
  385.     if (satp && sitep) {
  386.         sp = findSelectionbyName(satp, sitep);
  387.         if (!sp) {
  388.             SendMessage(hSelbox, LB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);
  389.             sbid = -1;
  390.         }
  391.         else if (sp->sl_index != sbid) {
  392.             *selpp = sp;
  393.             lselect(hSelbox, sbid = sp->sl_index);
  394.         }
  395.     }
  396.     return error;
  397. }
  398.  
  399. static void
  400. setControls(hwnd, satp, sitep, start, dur, step, minelev, upd, flags)
  401. HWND hwnd;
  402. satellite_t *satp;
  403. site_t *sitep;
  404. double start, dur, step, minelev;
  405. int upd,flags;
  406. {
  407.     double tstart;
  408.     int tupd;
  409.     BOOL r;
  410.     
  411.     if (satp) {
  412.         r = GetEditText(hwnd, IDC_SETTINGS_SATELLITE, tmpbuf, BUFLEN);
  413.         if (!r || strcmp(tmpbuf, satp->s_name)) {
  414.             SendMessage(hSatellite, WM_SETTEXT, (WPARAM) 0, (LPARAM) satp->s_name);
  415.             lselect(hSatListbox, satp->s_lbid);
  416.         }
  417.     }
  418.     if (sitep) {
  419.         r = GetEditText(hwnd, IDC_SETTINGS_LOCATION, textbuf, BUFLEN);
  420.         sprintf(tmpbuf,"%s, %s", sitep->c_name, sitep->c_locale);
  421.         if (!r || strcmp(textbuf, tmpbuf)) {
  422.             SendMessage(hSite, WM_SETTEXT, (WPARAM) 0, (LPARAM) tmpbuf);
  423.             lselect(hSiteListbox, sitep->c_lbid);
  424.         }
  425.     }
  426.  
  427.     r = GetEditText(hwnd, IDC_SETTINGS_GTR_STEPTIME, textbuf, BUFLEN);
  428.     if (!r || (atof(textbuf) != (step * SPD))) {
  429.         sprintf(tmpbuf,"%-.0lf", step * SPD);
  430.         SendMessage(hStepTime, WM_SETTEXT, (WPARAM) 0, (LPARAM) tmpbuf);
  431.     }
  432.  
  433.     r = GetEditText(hwnd, IDC_SETTINGS_GTR_DURATION, textbuf, BUFLEN);
  434.     if (!r || (atof(textbuf) != dur)) {
  435.         sprintf(tmpbuf,"%-.2lf", dur);
  436.         SendMessage(hDuration, WM_SETTEXT, (WPARAM) 0, (LPARAM) tmpbuf);
  437.     }
  438.  
  439.     r = GetEditText(hwnd, IDC_SETTINGS_MINELEVATION, textbuf, BUFLEN);
  440.     if (!r || (atof(textbuf) != (minelev*CRD))) {
  441.         sprintf(tmpbuf,"%-.0lf", minelev * CRD);
  442.         SendMessage(hMinElevation, WM_SETTEXT, (WPARAM) 0, (LPARAM) tmpbuf);
  443.     }
  444.  
  445.     r = GetEditText(hwnd, IDC_SETTINGS_GTR_STARTTIME, tmpbuf, BUFLEN);
  446.     if ((tmpbuf[0] == '*') && (tmpbuf[1] == 0))
  447.         tstart = -1.0;
  448.     else
  449.         tstart = dateStrtoTime(tmpbuf);
  450.         
  451.     if (!r || (start != tstart)) {
  452.         if (start != -1.0) {
  453.             dateStr(start, sitep, SE_GTR_UTC, 0, tmpbuf);
  454.             SendMessage(hStartTime, WM_SETTEXT, (WPARAM) 0, (LPARAM) tmpbuf);
  455.         }
  456.         else 
  457.             SendMessage(hStartTime, WM_SETTEXT, (WPARAM) 0, (LPARAM) "*");
  458.     }
  459.  
  460.     r = GetEditText(hwnd, IDC_SETTINGS_RTD_UPD, tmpbuf, BUFLEN);
  461.     tupd = -1;
  462.     sscanf(tmpbuf, "%d", &tupd);
  463.     if (!r || (tupd != upd)) {
  464.         sprintf(tmpbuf,"%d", upd);
  465.         SendDlgItemMessage(hwnd, IDC_SETTINGS_RTD_UPD, WM_SETTEXT, (WPARAM)0,
  466.             (LPARAM) tmpbuf);
  467.     }
  468.  
  469.     setbuttons(hwnd, flags);
  470. }
  471.  
  472.  
  473. static int
  474. setSel(hwnd, selp, satpp, sitepp, startp, durp, stepp, minelevp, updp, flagsp)
  475. HWND hwnd;
  476. select_t *selp;
  477. satellite_t **satpp;
  478. site_t **sitepp;
  479. double *startp, *durp, *stepp, *minelevp;
  480. int *updp;
  481. unsigned int *flagsp;
  482. {
  483.     track_t *tp;
  484.  
  485.     if (!selp)
  486.         return FALSE;
  487.  
  488.     if (currentSel != selp &&
  489.         ( (serverInfo[0].srv_state == ST_SRV_RUNNING) ||
  490.           (serverInfo[1].srv_state == ST_SRV_RUNNING)
  491.         ) && !yesno("Radio/Rotator Control running. Are you sure you want \
  492. to change the current satellite ?"))
  493.                 return 0;
  494.  
  495.     tp = selp->sl_tp;
  496.  
  497.     *satpp = tp->satp;
  498.     *sitepp = tp->sitep;
  499.     *startp = tp->starttime;
  500.     *durp = tp->duration;
  501.     *stepp = tp->steptime;
  502.     *minelevp = tp->minelevation;
  503.     *updp = selp->updatetime;
  504.     *flagsp = selp->flags;
  505.  
  506.     setControls(hwnd, tp->satp, tp->sitep, tp->starttime, tp->duration,
  507.         tp->steptime, tp->minelevation, selp->updatetime, selp->flags);
  508.  
  509.     currentSel = selp;
  510.  
  511.     lselect(hSelbox, selp->sl_index);
  512.     return 1;
  513. }
  514.  
  515. BOOL CALLBACK
  516. GetSetProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  517. {
  518.         POINT *p;
  519.         static site_t *sitep;
  520.         static satellite_t *satp;
  521.         static select_t *selp;
  522.         static int flag; /* must be static */
  523.         static int flags;
  524.         static int updateTime;
  525.         int i, cmd;
  526.         HDC hdc;
  527.         extern HFONT hPica;
  528.         select_t *tmpsp;
  529.  
  530.         if (message == WM_MOUSEMOVE)
  531.             return TRUE;
  532.             
  533.         switch(message) {
  534.             case WM_INITDIALOG:
  535.                 p = DialogPos(Gwnd, hwnd);
  536.                 hSiteListbox = GetDlgItem(hwnd, IDC_SETTINGS_SITELIST);
  537.                 hSelbox = GetDlgItem(hwnd, IDC_SETTINGS_SELLIST);
  538.                 SendMessage(hSelbox, WM_SETFONT, (WPARAM) hPica, (LPARAM)
  539.                     MAKELPARAM(TRUE, 0));
  540.                 hSatListbox = GetDlgItem(hwnd, IDC_SETTINGS_SATLIST);
  541.                 hSite = GetDlgItem(hwnd, IDC_SETTINGS_LOCATION);
  542.                 hSatellite = GetDlgItem(hwnd, IDC_SETTINGS_SATELLITE);
  543.                 hMinElevation = GetDlgItem(hwnd, IDC_SETTINGS_MINELEVATION);
  544.                 hStartTime = GetDlgItem(hwnd, IDC_SETTINGS_GTR_STARTTIME);
  545.                 hDuration = GetDlgItem(hwnd, IDC_SETTINGS_GTR_DURATION);
  546.                 hStepTime = GetDlgItem(hwnd, IDC_SETTINGS_GTR_STEPTIME);
  547.                 listSites(hSiteListbox);
  548.                 listSatellites(hSatListbox);
  549.                 listSelections(hSelbox);
  550.                 clrbtnflgs();
  551.  
  552.                 selp = currentSel;
  553.                 if (!selp)
  554.                     selp = selInfo;
  555.                 if (selp) {
  556.                     sbid = selp->sl_index;
  557.                     setSel(hwnd, selp, &satp, &sitep, &startTime, &duration,
  558.                         &stepTime, &minElevation, &updateTime, &flags);
  559.                 }
  560.                 SendMessage(hwnd, DM_SETDEFID, (WPARAM) IDNONE, (LPARAM)0 );
  561.                 SendMessage(GetDlgItem(hwnd, IDOK), WM_SETFOCUS, 0, (LPARAM)0);
  562.                 SetWindowPos(hwnd, 0, (int)p->x, (int)p->y, 0, 0,
  563.                          SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
  564.  
  565.                 return TRUE;
  566.  
  567.             case WM_COMMAND:
  568.                 if ((cmd = checkbuttons(hwnd, wParam, &flags)) >= 0) {
  569.                     switch (cmd) {
  570.                     case IDOK:
  571.                         EndDialog(hwnd, wParam);
  572.                         return TRUE;
  573.  
  574.                     case IDSAVE:
  575.                         saveactivelist();
  576.                         return TRUE;
  577.  
  578.                     case IDMORE:
  579.                         MoreHook(hwnd, selp, satp, sitep, &flags);
  580.                         return TRUE;
  581.  
  582.                     case IDADDSEL:
  583.                         selp = addSelection(satp, sitep, startTime, duration,
  584.                                     stepTime, minElevation, updateTime, flags);
  585.                         if (!selp)
  586.                             return TRUE;
  587.  
  588.                         i = SendMessage(hSelbox, LB_ADDSTRING, (WPARAM)0,
  589.                                            (LPARAM) selp->sl_buf);
  590.                         if (i == LB_ERR) {
  591.                             usermsg("No space left in active list");
  592.                             deleteSelection(selp);
  593.                               break;
  594.                         }
  595.                         selp->sl_index = sbid = i;        /* IMPORTANT */
  596.                         setSel(hwnd, selp, &satp, &sitep, &startTime,
  597.                                &duration, &stepTime, &minElevation,
  598.                                &updateTime, &flags);
  599.                                                                 
  600.                         sbid = selp->sl_index;
  601.                         return TRUE;
  602.  
  603.                     case IDMODIFY:
  604.                         OnReturn(hwnd, &selp, &satp, &lsat, &sitep, &lsite,
  605.                             &startTime, &duration, &stepTime, &minElevation,
  606.                             &updateTime);
  607.                         if (modifySelectionbyName(hSelbox, selp, satp, sitep,
  608.                             startTime, duration, stepTime, minElevation,
  609.                                 updateTime, flags)) {
  610.                             setSel(hwnd, selp, &satp, &sitep, &startTime,
  611.                                     &duration, &stepTime, &minElevation,
  612.                                     &updateTime, &flags);
  613.                             sbid = selp->sl_index;
  614.                         }
  615.                         return TRUE;
  616.  
  617.                     case IDDELSEL:
  618.                         if (selp)
  619.                             sbid = selp->sl_index;
  620.  
  621.                         if (sbid >= 0)
  622.                             selp = findSelectionbyID(sbid);
  623.  
  624.                         if (deleteSelection(selp) >= 0) {
  625.                             SendMessage(hSelbox, LB_DELETESTRING,
  626.                                 (WPARAM) sbid, (LPARAM) 0);
  627.                             sbid -= 1;
  628.                             selp = findSelectionbyID(sbid);
  629.                             if (selp) {
  630.                                 setSel(hwnd, selp, &satp, &sitep,
  631.                                     &startTime, &duration, &stepTime,
  632.                                     &minElevation, &updateTime, &flags);
  633.                             }
  634.                         }
  635.                         return TRUE;
  636.  
  637.                     case IDC_SETTINGS_SHOWSAT:
  638.                         if (satp)
  639.                             showSatellite(hwnd, satp);
  640.                         return TRUE;
  641.  
  642.                     case IDC_SETTINGS_SHOWLOC:
  643.                         if (sitep)
  644.                             showSite(hwnd, sitep);
  645.                         return TRUE;
  646.  
  647.                     default:
  648.                         break;
  649.                     }
  650.                     return TRUE;
  651.                 }
  652.  
  653.                 if (LOWORD(wParam) == IDNONE) {
  654.                     OnReturn(hwnd, &selp, &satp, &lsat, &sitep, &lsite,
  655.                         &startTime, &duration, &stepTime, &minElevation,
  656.                         &updateTime);
  657.                     return TRUE;
  658.                 }
  659.                 cmd = HIWORD(wParam);
  660.  
  661.                 if (cmd == EN_CHANGE) {
  662.                     switch(LOWORD(wParam)) {
  663.                     case IDC_SETTINGS_SATELLITE:
  664.                         tmpbuf[0] = 0;
  665.                         GetEditText(hwnd, IDC_SETTINGS_SATELLITE, tmpbuf, BUFLEN);
  666.                         i = SendMessage(hSatListbox, LB_SELECTSTRING,
  667.                                 (WPARAM) -1, (LPARAM) tmpbuf);
  668.                         if (i != LB_ERR) {
  669.                             if (i != lsat)
  670.                                 lselect(hSatListbox, lsat = i);
  671.                         }
  672.                         else
  673.                             lsat = -1;
  674.                         break;
  675.  
  676.                     case IDC_SETTINGS_LOCATION:
  677.                         string[0] = 0;
  678.                         GetEditText(hwnd, IDC_SETTINGS_LOCATION, string, BUFLEN);
  679.                         i = SendMessage(hSiteListbox, LB_SELECTSTRING,
  680.                             (WPARAM) -1, (LPARAM) string);
  681.                         if (i != LB_ERR) {
  682.                             if (i != lsite)
  683.                                 lselect(hSiteListbox, lsite = i);
  684.                         }
  685.                         else
  686.                             lsite = -1;
  687.                         break;
  688.                     }
  689.                     SendMessage(hwnd, DM_SETDEFID, (WPARAM)IDNONE, (LPARAM)0);
  690.                     return TRUE;
  691.                 }
  692.  
  693.                 if (cmd == LBN_SELCHANGE) {
  694.                     switch (LOWORD(wParam)) {
  695.                     case IDC_SETTINGS_SELLIST:
  696.                         i = SendMessage(hSelbox, LB_GETCURSEL, (WPARAM)0 , (LPARAM) 0);
  697.                         if (i == LB_ERR)
  698.                             break;
  699.                         if ((tmpsp = findSelectionbyID(i)) == NULL)
  700.                             break;
  701.                         if (setSel(hwnd, tmpsp, &satp, &sitep, &startTime, &duration,
  702.                                &stepTime, &minElevation, &updateTime, &flags)) {
  703.                             selp = tmpsp;
  704.                             sbid =  selp->sl_index;
  705.                             lsite = sitep->c_lbid;
  706.                             lsat =  satp->s_lbid;
  707.                             break;
  708.                         }
  709.                         if (selp)
  710.                             lselect(hSelbox, sbid = selp->sl_index);
  711.                         break;
  712.  
  713.                     case IDC_SETTINGS_SITELIST:
  714.                         i = SendDlgItemMessage(hwnd, IDC_SETTINGS_SITELIST,
  715.                                 LB_GETCURSEL, (WPARAM) 0 , (LPARAM) 0 );
  716.                         if (i != LB_ERR && i != lsite) {
  717.                             sitep = findSitebyID(lsite = i);
  718.                             sprintf(tmpbuf,"%s, %s", sitep->c_name, sitep->c_locale);
  719.                             SendMessage(hSite, WM_SETTEXT,
  720.                                    (WPARAM) 0, (LPARAM) tmpbuf);
  721.                             lsite = sitep->c_lbid;
  722.                         }
  723.                         goto dosel;
  724.  
  725.                     case IDC_SETTINGS_SATLIST :
  726.                         i = SendMessage(hSatListbox, LB_GETCURSEL,
  727.                                 (WPARAM)0 , (LPARAM)0 );
  728.                         if (i != LB_ERR && i != lsat) {
  729.                             satp = findSatbyID(lsat = i);
  730.                             SendMessage(hSatellite, WM_SETTEXT,
  731.                                         (WPARAM) 0, (LPARAM) satp->s_name);
  732.                         }
  733.                       dosel:
  734.                           tmpsp = findSelectionbyName(satp, sitep);
  735.                           if (tmpsp && selp != tmpsp) {
  736.                               sbid = tmpsp->sl_index;
  737.                             setSel(hwnd, selp = tmpsp, &satp, &sitep,
  738.                                    &startTime, &duration, &stepTime,
  739.                                    &minElevation, &updateTime, &flags);
  740.                         }
  741.                         break;
  742.                         
  743.                     default:
  744.                         break;
  745.                     }
  746.                     SendMessage(hwnd, DM_SETDEFID, (WPARAM)IDNONE, (LPARAM)0);
  747.                     return TRUE;
  748.                 }
  749.                 break;
  750.  
  751.             case WM_CLOSE:                
  752.                 PostMessage(hwnd, WM_COMMAND, (WPARAM) IDOK, (LPARAM) 0);
  753.                 return TRUE;
  754. #define DARKGRAY    7
  755. #define LIGHTGRAY   8
  756.             case WM_CTLCOLORLISTBOX:
  757. #ifdef TACKYCOLORS
  758.                 if ((HWND)lParam == hSelbox) {
  759.                     ColorSet(wParam, CWHITE, 5);
  760.                     return (BOOL) hDrawBrush[5];
  761.                 }
  762. #endif
  763.                 ColorSet(wParam, CWHITE, DARKGRAY);
  764.                 return (BOOL) hDrawBrush[DARKGRAY];
  765.  
  766.             case WM_CTLCOLOREDIT:
  767.                 ColorSet(wParam, CWHITE, 6);
  768.                 return (BOOL) hDrawBrush[6];
  769.                 
  770.             case WM_PAINT:                
  771.                 hdc = GetDC(hwnd);
  772.                 DrawIcon(hdc, 458, 135, hVersa);
  773.                 ReleaseDC(hwnd, hdc);
  774.                 break;
  775.                 
  776.             case WM_CTLCOLORDLG:
  777.                 ColorSet(wParam, CBLACK, LIGHTGRAY);
  778.                 return (BOOL) hDrawBrush[LIGHTGRAY];
  779.  
  780.             case WM_CTLCOLORSTATIC:
  781.             case WM_CTLCOLORMSGBOX:
  782.             case WM_CTLCOLORBTN:
  783.                 ColorSet(wParam, CBLACK, LIGHTGRAY);
  784.                 return (BOOL) hDrawBrush[LIGHTGRAY]; 
  785.  
  786.             case WM_CTLCOLORSCROLLBAR:
  787.                 ColorSet(wParam, CBLACK, 6);
  788.                 return (BOOL) hDrawBrush[6];
  789.  
  790.             default:
  791.                 break;
  792.         }
  793.         return FALSE;
  794. }
  795.  
  796.        
  797. BOOL
  798. GetEditText(hwnd, ItemId, buf, maxlen)
  799. HWND hwnd;
  800. int ItemId;
  801. char *buf;
  802. int maxlen;
  803. {
  804.     int i;
  805.     char tbuf[80], *cp;
  806.     
  807.     i = SendDlgItemMessage(hwnd, ItemId, (UINT)WM_GETTEXTLENGTH, (WPARAM) 0, (LPARAM) 0);
  808.  
  809.     if (i <=0 || i >= sizeof(tbuf)-1)
  810.         return FALSE;
  811.     else if (i > 0) {
  812.         SendDlgItemMessage(hwnd, ItemId, (UINT)WM_GETTEXT, (WPARAM) i+1, (LPARAM) tbuf);
  813.         tbuf[i+1] = 0;
  814.         cp = stripLeadingSpace(tbuf);
  815.         strncpy(buf, cp, sizeof(tbuf));
  816.         stripTrailingSpace(buf);
  817.     }
  818.  
  819.     return TRUE;
  820. }
  821.  
  822.